/****** Object:  Table [dbo].[Document]    Script Date: 09/07/2006 14:39:55 ******/
CREATE TABLE [dbo].[Document](
	[Id] [int] NOT NULL,
	[Name] [char](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_Document] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


/****** Object:  Table [dbo].[Path]    Script Date: 09/07/2006 14:43:47 ******/
CREATE TABLE [dbo].[Path](
	[PathId] [int] NOT NULL,
	[PathExp] [char](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_Path] PRIMARY KEY CLUSTERED 
(
	[PathId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE UNIQUE NONCLUSTERED INDEX [IX_Path] ON [dbo].[Path] 
(
	[PathExp] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]



/****** Object:  Table [dbo].[DocumentRValue]    Script Date: 09/07/2006 14:44:02 ******/
CREATE TABLE [dbo].[DocumentRValue](
	[DocId] [int] NOT NULL,
	[Level] [int] NOT NULL,
	[RValue] [bigint] NULL,
 CONSTRAINT [PK_DocumentRValue] PRIMARY KEY CLUSTERED 
(
	[DocId] ASC,
	[Level] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
/* Foreign Key
ALTER TABLE [dbo].[DocumentRValue]  WITH NOCHECK ADD  CONSTRAINT [FK_DocumentRValue_Document] FOREIGN KEY([DocId])
REFERENCES [dbo].[Document] ([Id])
ALTER TABLE [dbo].[DocumentRValue] CHECK CONSTRAINT [FK_DocumentRValue_Document]
*/


/****** Object:  Table [dbo].[PathValue]    Script Date: 09/07/2006 14:44:22 ******/
CREATE TABLE [dbo].[PathValue](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[BranchOrder] [int] NULL,
	[PathId] [int] NULL,
	[DeweyOrderSum] [bigint] NOT NULL,
	[SiblingSum] [bigint] NULL,
	[LeafValue] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_PathValue] PRIMARY KEY CLUSTERED 
(
	[DocId] ASC,
	[DeweyOrderSum] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_PathValue_1] ON [dbo].[PathValue] 
(
	[SiblingSum] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_PathValue_2] ON [dbo].[PathValue] 
(
	[PathId] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

CREATE UNIQUE NONCLUSTERED INDEX [IX_PathValue_3] ON [dbo].[PathValue] 
(
	[DocId] ASC,
	[LeafOrder] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

/* Foreign Key
ALTER TABLE [dbo].[PathValue]  WITH NOCHECK ADD  CONSTRAINT [FK_PathValue_Document] FOREIGN KEY([DocId])
REFERENCES [dbo].[Document] ([Id])
ALTER TABLE [dbo].[PathValue] CHECK CONSTRAINT [FK_PathValue_Document]

ALTER TABLE [dbo].[PathValue]  WITH NOCHECK ADD  CONSTRAINT [FK_PathValue_Path] FOREIGN KEY([PathId])
REFERENCES [dbo].[Path] ([PathId])
ALTER TABLE [dbo].[PathValue] CHECK CONSTRAINT [FK_PathValue_Path]
*/


/****** Object:  Table [dbo].[Attribute]    Script Date: 09/07/2006 14:44:34 ******/
CREATE TABLE [dbo].[Attribute](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[PathId] [int] NOT NULL,
	[LeafValue] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
 CONSTRAINT [PK_Attribute] PRIMARY KEY CLUSTERED 
(
	[DocId] ASC,
	[LeafOrder] ASC,
	[PathId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

/* Foreign Key
ALTER TABLE [dbo].[Attribute]  WITH NOCHECK ADD  CONSTRAINT [FK_Attribute_Path] FOREIGN KEY([PathId])
REFERENCES [dbo].[Path] ([PathId])
ALTER TABLE [dbo].[Attribute] CHECK CONSTRAINT [FK_Attribute_Path]

ALTER TABLE [dbo].[Attribute]  WITH NOCHECK ADD  CONSTRAINT [FK_Attribute_PathValue] FOREIGN KEY([DocId], [LeafOrder])
REFERENCES [dbo].[PathValue] ([DocId], [LeafOrder])
ALTER TABLE [dbo].[Attribute] CHECK CONSTRAINT [FK_Attribute_PathValue]
*/


/****** Object:  Table [dbo].[TextContent]    Script Date: 09/07/2006 14:44:46 ******/
/* Not used
CREATE TABLE [dbo].[TextContent](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[BranchOrder] [int] NULL,
	[PathId] [int] NULL,
	[DeweyOrderSum] [bigint] NULL,
	[SiblingSum] [bigint] NULL,
	[LeafValue] [char](8000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_TextContent] PRIMARY KEY CLUSTERED 
(
	[DocId] ASC,
	[LeafOrder] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[TextContent]  WITH CHECK ADD  CONSTRAINT [FK_TextContent_Document] FOREIGN KEY([DocId])
REFERENCES [dbo].[Document] ([Id])
ALTER TABLE [dbo].[TextContent]  WITH CHECK ADD  CONSTRAINT [FK_TextContent_Path] FOREIGN KEY([PathId])
REFERENCES [dbo].[Path] ([PathId])
*/


